package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.hjq.shape.view.ShapeButton;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.bean.PostBean;

/**
 * Author: lkw
 * time:   2021/9/14 15:54
 * des:    选择岗位Dialog适配器
 */
public class ChoosePostAdapter extends AppAdapter<PostBean> {
    private int selPosition = -1;
    public ChoosePostAdapter(@NonNull Context context) {
        super(context);
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            return new OtherViewHolder();
    }

    private final class OtherViewHolder extends AppAdapter<?>.ViewHolder {

        private final ShapeButton mReason;

        private OtherViewHolder() {
            super(R.layout.item_choose_reason);
            mReason = findViewById(R.id.btn_reason);
        }

        @Override
        public void onBindView(int position) {
            PostBean bean = getItem(position);
            if (position == selPosition) {
                setTag(position);
                mReason.setText(bean.getName());
                mReason.getShapeDrawableBuilder()
                        .setSolidColor(ContextCompat.getColor(getContext(), R.color.color_EAF4FF))
                        .intoBackground();
                mReason.getTextColorBuilder()
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.color_4181fe))
                        .intoTextColor();
            } else {
                mReason.setText(bean.getName());
                mReason.getShapeDrawableBuilder()
                        .setSolidColor(ContextCompat.getColor(getContext(), R.color.white))
                        .intoBackground();
                mReason.getTextColorBuilder()
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.color_151515))
                        .intoTextColor();
            }
        }
    }
    public void setItemSel(int selPosition) {
        this.selPosition = selPosition;
        notifyDataSetChanged();
    }
}
